package com.zhongyu.scheduler.consumer.controller;

import com.zhongyu.comm.util.OrderException;
import com.zhongyu.comm.vo.CreateOrderVo;
import com.zhongyu.comm.vo.Result;
import com.zhongyu.scheduler.consumer.service.SchedulerSeatPriceService;
import com.zhongyu.scheduler.consumer.service.SchedulerSeatService;
import com.zhongyu.scheduler.consumer.service.SchedulerService;
import com.zhongyu.scheduler.consumer.vo.CinemaSeatVo;
import com.zhongyu.scheduler.consumer.vo.SchedulerSeatPriceVo;
import com.zhongyu.scheduler.consumer.vo.SchedulerVo;
import com.zhongyu.scheduler.consumer.vo.SeatArrayVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
public class SchedulerController {

            @Resource
            private SchedulerService schedulerService;

            @Resource
            private SchedulerSeatPriceService schedulerSeatPriceService;

            @Resource
            private SchedulerSeatService schedulerSeatService;

            @RequestMapping("/p/queryItemScheduler")
            public Result queryItemScheduler(@RequestBody SchedulerVo vo){
                List<SchedulerVo> list=schedulerService.createOrder(vo.getItemId());
                return Result.success(list);
            }

            @RequestMapping("/p/queryItemPrice")
            public Result queryItemPrice(@RequestBody SchedulerSeatPriceVo vo){
                List<SchedulerSeatPriceVo> list= schedulerSeatPriceService.queryItemPrice(vo.getScheduleId());
                return Result.success(list);
            }

            @RequestMapping("/p/queryOriginalCinemaSeatArray")
            public Result queryOriginalCinemaSeatArray(@RequestBody CinemaSeatVo cinemaSeatVo){
                SeatArrayVo seatArrayVo=schedulerSeatService.queryOriginalCinemaSeatArray(cinemaSeatVo.getScheduleId());
                return Result.success(seatArrayVo);

            }
            @RequestMapping("/p/queryCinemaSeatArrayByScheduleId")
            public Result queryCinemaSeatArrayByScheduleId(@RequestBody CinemaSeatVo cinemaSeatVo){
                cinemaSeatVo=schedulerSeatService.queryCinemaSeatArrayByScheduleId(cinemaSeatVo.getScheduleId(),cinemaSeatVo.getCinemaId());
                return Result.success(cinemaSeatVo);
            }

            @RequestMapping("/v/createOrder")
            public Result createOrder(@RequestBody CreateOrderVo createOrderVo){
                try {
                    log.debug("linkeIdS:"+createOrderVo);
                    String orderNo= schedulerSeatService.lockSeatAndUpdate(createOrderVo);
                    return Result.success(orderNo);
                } catch (OrderException e) {
            log.error("创建订单失败",e);
            return Result.failure(e.getMessage());
        }

    }

}
